<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jsencrypt/3.0.0-beta.1/jsencrypt.js"></script>
    <script type="text/javascript">
        //公钥

        var PUBLIC_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHRJ61oHamaXjQwSpwPh5xOl5z\n' +
            'FE25stCxWgTUrQZSqpxksfKeR9qsTaGAt9bJ2LfOb8DKxzHEqRDqiUV7bdbemE0D\n' +
            'leJfOHPyPhQnBx/zmNbfKp5dRQtT1EFu0zxCXJW750N+3FWPhwx4DLvz1VFpWqWg\n' +
            'IyDK4UliWCmDCeppkQIDAQAB';
        //私钥
        var PRIVATE_KEY = 'MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMdEnrWgdqZpeNDB\n' +
            'KnA+HnE6XnMUTbmy0LFaBNStBlKqnGSx8p5H2qxNoYC31snYt85vwMrHMcSpEOqJ\n' +
            'RXtt1t6YTQOV4l84c/I+FCcHH/OY1t8qnl1FC1PUQW7TPEJclbvnQ37cVY+HDHgM\n' +
            'u/PVUWlapaAjIMrhSWJYKYMJ6mmRAgMBAAECgYAegkESadkArZFT1N9chAZBK8Ce\n' +
            'OfOUhO4y2Sd4MG2RZpG/UQdmeHXgf5pEjOET0lyB/NY1tb3G8GOopQ/AUBbfhJ1M\n' +
            'RASXX8SXy7eTB9/OZu9cLHsmrXxTKckMwLXkipYMGQaiBuioXkxwTIwIPqQRUrgR\n' +
            'tOcn35LbAnf/ZhYp4QJBAOh5eHj48AtZbNpVQWXtmM83N1Uc7gziqyXpKh4rKA/U\n' +
            'PoCkKhM3sFply2TzaMpnIqBlxfx6YFhIE59XlVSyGEUCQQDbbuWMo1bg3u7nkDBL\n' +
            'p6hUN7zCSSx14BUpG/D6mXbzpgUnsCSg1tx/I+3kpki99Y3WorsNEFPPTREmc0ca\n' +
            'q/7dAkBWVf5i1vi3Dk/5yd3Oz+2HT1dSWbsit++d1bkZmSd4sXdA6TbjCjSJbfKa\n' +
            'nDdXq/PVI9bijERJpQL8k1dXLAkNAkB32nae/ohxgtLSwDrg185lUZxUMkuKhr6I\n' +
            'Ga7h8fi61C90og0fnLwK5cEGZpzMxNaYKYIpfIWKcPmxGr33n4IxAkBHbZLAfJn5\n' +
            'fKLSdkZ9yrwTVb8+BlLnvQmqYQYcX6IAEQy1T3Pd19gNu9qkpxd02pASpWc1JbOs\n' +
            'lb5bG+lx8++8';
        //使用公钥加密
        var encrypt = new JSEncrypt();
        //encrypt.setPrivateKey('-----BEGIN RSA PRIVATE KEY-----'+PRIVATE_KEY+'-----END RSA PRIVATE KEY-----');
        encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');
        var encrypted = encrypt.encrypt('你好加密');
        console.log('加密后数据:%o', encrypted);
        //使用私钥解密
        var decrypt = new JSEncrypt();
        //decrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');
        decrypt.setPrivateKey('-----BEGIN RSA PRIVATE KEY-----'+PRIVATE_KEY+'-----END RSA PRIVATE KEY-----');
        var uncrypted = decrypt.decrypt(encrypted);
        console.log('解密后数据:%o', uncrypted);
    </script>

</head>
<body>

</body>
</html>